# Maintainer: Peter Budai <peterbudai@hotmail.com>

_realname=scikit-learn
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.2.0
pkgrel=1
pkgdesc="A set of python modules for machine learning and data mining (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64')
url='https://scikit-learn.org'
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-numpy"
         "${MINGW_PACKAGE_PREFIX}-python-scipy"
         "${MINGW_PACKAGE_PREFIX}-python-joblib"
         "${MINGW_PACKAGE_PREFIX}-python-threadpoolctl")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-wheel"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        001-mingw-python-openmp-flag.patch
        002-openmp-cleanup-wait.patch
        003-Fix-optimization-flag.patch)
sha256sums=('680b65b3caee469541385d2ca5b03ff70408f6c618c583948312f0d2125df680'
            '7817f0ac38fd47fb5731abf6ba76f0e8d6534f98e085048d0bc9cb5e402c8d43'
            'b9e8d52dd9f989c8b75c086653690598f28378451fbd7078e8163bff1d76452e'
            '28b5bb841050cce6e77e6ce9078097ed39e6ff0e2ff3f20b12368701bf92ff3c')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-mingw-python-openmp-flag.patch
  patch -p1 -i ${srcdir}/002-openmp-cleanup-wait.patch
  patch -p1 -i ${srcdir}/003-Fix-optimization-flag.patch

  cd ${srcdir}
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE

  install -d ${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}
  cp -r doc/tutorial ${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}/tutorial
}
